package co.chonghao.ch_kuaichong_user.ui.activitys;

import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import co.chonghao.ch_kuaichong_user.R;
import co.chonghao.ch_kuaichong_user.app.App;
import co.chonghao.ch_kuaichong_user.bean.MainTabs;


public class MainActivity extends AppCompatActivity {

    private FragmentTabHost mFtabMainBottomLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        App.initStaus(this);
        App.getInstance().addActivity(this);


        init();


    }


    private void init() {

        //初始化底部
        //1. 跟显示的界面关联
        //2. 初始化底部页签
        mFtabMainBottomLayout = (FragmentTabHost) findViewById(R.id.ftab_main_bottom_layout);
        //关联
        mFtabMainBottomLayout.setup(this, getSupportFragmentManager(), R.id.fl_main_show_layout);
        MainTabs[] tabses = MainTabs.values();
        for (int i = 0; i < tabses.length; i++) {
            Bundle args = new Bundle();
            args.putString("point", i + "");
            addTab(tabses[i], args, i);
        }

        //去掉分隔线
        mFtabMainBottomLayout.getTabWidget().setDividerDrawable(null);
    }


    //添加页签
    private void addTab(MainTabs tabse, Bundle args, int point) {
        TabHost.TabSpec tabspac = mFtabMainBottomLayout.newTabSpec(tabse.mTag);// 复用

        //设置显示的view
        View view = View.inflate(this, R.layout.tab_indicator, null);

        //动态的设置文字
        TextView title = (TextView) view.findViewById(R.id.tab_title);
        title.setText(tabse.mTitle);
        //动态的设置图片
        ImageView icon = (ImageView) view.findViewById(R.id.iv_icon);
        icon.setImageResource(tabse.mImage);


        tabspac.setIndicator(view);

        Class<?> clss = tabse.mClss;
        mFtabMainBottomLayout.addTab(tabspac, clss, args);
    }

    //初始化沉浸式状态栏

}
